//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//********************************************************* 

using System.Windows.Forms;
using Microsoft.TridentWordAddIn.Common;
using Microsoft.TridentWordAddIn.ResourceHelper;

namespace Microsoft.TridentWordAddIn.Presentation
{
    internal partial class ProtectDocumentForm : BaseForm
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ProtectDocumentForm"/> class.
        /// </summary>
        public ProtectDocumentForm()
        {
            this.InitializeComponent();
        }

        /// <summary>
        /// Gets the password entered.
        /// </summary>
        /// <value>The password entered.</value>
        public string Password
        {
            get { return this.txtPassword.Text.Trim(); }
        }

        /// <summary>
        /// Handles the FormClosing event of the ProtectDocumentForm control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.FormClosingEventArgs"/> instance containing the event data.</param>
        private void ProtectDocumentForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult.OK == this.DialogResult)
            {
                if (this.txtPassword.Text.IsNullOrEmpty() && this.txtConfirmPassword.Text.IsNullOrEmpty())
                {
                    MessageBoxHelper.ShowDefault(ResourceFetcher.GetString("EmptyPassword"), MessageBoxIcon.Error);
                    e.Cancel = true;
                }
                else if (!this.txtPassword.Text.Compare(this.txtConfirmPassword.Text))
                {
                    MessageBoxHelper.ShowDefault(ResourceFetcher.GetString("InvalidConfirmPassword"), MessageBoxIcon.Error);
                    e.Cancel = true;
                }
            }
        }
    }
}